def isright(b):
    if 'A' not in b:
        if 'B' not in b:
            return 0
    if 'A' in b:
        if 'D' in b:
            return 0
    c=0
    for i in range(len(b)):
        if b[i]=='A':
            c=c+1
        if b[i]=='E':
            c=c+1
        if b[i]=='F':
            c=c+1
    if c!=2:
        return 0
    if 'B' in b:
        if 'C' not in b:
            return 0
    else:
        if 'C' in b:
            return 0
    if 'C' in b:
        if 'D' in b:
            return 0
    else:
        if 'D' not in b:
            return 0
    if 'D' not in b:
        if 'E' in b:
            return 0
    return 1
a=['A','B','C','D','E','F']
for m in range(1,5):
    p=0
    while 1:
        c=a[p]
        b=[c]
        while b:
            for i in a[a.index(c)+1:]:
                if i not in b:
                    b.append(i)
                    if len(b)>m:
                        if isright(b)==1:
                            print b
                        break
            c=b.pop()
        p=p+1
        if p==len(a):
            break
